//
//  NavigationViewController.m
//  Lextra Junior ueb IT
//
//  Created by Dirk Lieder on 27.05.11.
//  Copyright 2011 Phosphon. All rights reserved.
//

#import "NavigationViewController.h"

#import "Lextra_Engine.h"


@implementation NavigationViewController


@synthesize navigationBar;


//@synthesize navigationItem;

static BOOL delite;
static BOOL selfAkt=true;


- (void)setDelegate:(id)new_delegate{
	Delegate = new_delegate;
}



- (void)showNavigationText:(NSString*)navigationText deliteView:(BOOL)deliteView{
    
	UINavigationItem *navItem;
	if(!selfAkt){
        
		/*
		navItem = [UINavigationItem alloc];
		navItem.title = navigationText;
		[navigationBar pushNavigationItem:navItem animated:YES];
		[navigationBar setDelegate:self];
        */
        
        
	}
    //if(selfAkt){
        if(deliteView){
            delite = true;
            
            do{
                navItem = [navigationBar popNavigationItemAnimated:FALSE];
            } while(navItem != nil);
            
            delite = false;			
        } else {
        
        }
	//}
    navItem = [UINavigationItem alloc];
    navItem.title = navigationText;
    [navigationBar pushNavigationItem:navItem animated:YES];
    [navigationBar setDelegate:self];
   
    selfAkt = true;
}

- (void)backText{
    [navigationBar popNavigationItemAnimated:TRUE];
    selfAkt = true;
}


- (id)createNavigationButton:(NSString*)navigationText callback:(id)callback{
    
    NSLog(@"--%@", navigationText);
    
    barButtonItem = [[UIBarButtonItem alloc] initWithTitle:navigationText
                                    style:UIBarButtonItemStyleBordered
                                    target:callback
                                    action:@selector(nextBarButtonClicked)];
    
    [navigationBar.topItem setRightBarButtonItem:barButtonItem];
    [barButtonItem release];

    
    return barButtonItem;
}

- (void)removeNavigationButton{
    
}



- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigationItem *)item{
	
	if(!delite) {
		selfAkt = true;
		[Delegate closeNavigation];
		selfAkt = false;
	}
	return(true);
}


#pragma mark - View lifecycle

- (void)viewDidLoad
{
    
    delite = false;
	selfAkt = false;
                
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
